<?php

/**
 * inscription actions.
 *
 * @package    espace14
 * @subpackage inscription
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class inscriptionActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
//    $this->inscriptionss = Doctrine_Core::getTable('inscriptions')
//      ->createQuery('a')
//      ->execute();
	 $q = Doctrine_Query::create()
	  ->from('Inscriptions i')
	  ->leftJoin('i.Modules m')
	  ->leftJoin ('i.SfGuardUser s')
	  ->where('i.id_module = m.id')
	  ->andWhere('i.id_sf_guard_user = s.id');
//	  ->execute();
	  $this->inscriptionss = $q->fetchArray();
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->inscriptions = Doctrine_Core::getTable('inscriptions')->find(array($request->getParameter('id')));
    $this->forward404Unless($this->inscriptions);
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new inscriptionsForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new inscriptionsForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($inscriptions = Doctrine_Core::getTable('inscriptions')->find(array($request->getParameter('id'))), sprintf('Object inscriptions does not exist (%s).', $request->getParameter('id')));
    $this->form = new inscriptionsForm($inscriptions);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($inscriptions = Doctrine_Core::getTable('inscriptions')->find(array($request->getParameter('id'))), sprintf('Object inscriptions does not exist (%s).', $request->getParameter('id')));
    $this->form = new inscriptionsForm($inscriptions);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($inscriptions = Doctrine_Core::getTable('inscriptions')->find(array($request->getParameter('id'))), sprintf('Object inscriptions does not exist (%s).', $request->getParameter('id')));
    $inscriptions->delete();

    $this->redirect('inscription/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $inscriptions = $form->save();

      $this->redirect('inscription/edit?id='.$inscriptions->getId());
    }
  }
}
